<template>
  <div class="login-container">
    <!-- Logo与标题 -->
    <div class="app-header">
      <h1>欢迎使用</h1>
      <h2>农业机械云平台</h2>
    </div>

    <!-- 登录表单部分 -->
    <div class="login-content">
      <el-tabs v-model="activeTab" type="border-card">
        <el-tab-pane label="账号密码登录" name="password">
          <el-form :model="form" class="login-form">
            <el-form-item>
              <el-input
                v-model="form.username"
                placeholder="用户名/工号/手机号"
                prefix-icon="el-icon-user"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="form.password"
                placeholder="密码"
                type="password"
                prefix-icon="el-icon-lock"
              />
            </el-form-item>
            <el-form-item class="options">
              <div class="checkbox-container">
                <el-checkbox v-model="form.remember">记住密码</el-checkbox>
                <a href="#" class="forget-link" @click.prevent="onForgetPassword">忘记密码</a>
              </div>
            </el-form-item>
            <el-form-item class="login-center">
              <el-button type="primary" class="login-button" @click="handleLogin">立即登录</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="手机号登录" name="phone">
          <el-form :model="form" class="login-form">
            <el-form-item>
              <el-input
                v-model="form.phone"
                placeholder="手机号"
                prefix-icon="el-icon-mobile"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="form.captcha"
                placeholder="验证码"
                prefix-icon="el-icon-message"
              />
              <el-button type="text" @click="sendCaptcha">获取验证码</el-button>
            </el-form-item>
            <el-form-item class="login-center">
              <el-button type="primary" class="login-button" @click="handleLogin">立即登录</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 底部语言选项 -->
    <footer class="footer-links">
      <a href="#">中文简体</a>
      <a href="#">中文繁体</a>
      <a href="#">English</a>
    </footer>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeTab: "password",
      form: {
        username: "",
        password: "",
        phone: "",
        captcha: "",
        remember: false,
      },
    };
  },
  methods: {
    handleLogin() {
      const validUsername = "admin";
      const validPassword = "123456";

      if (
        this.activeTab === "password" &&
        this.form.username === validUsername &&
        this.form.password === validPassword
      ) {
        this.$store.commit("SET_USER", { username: validUsername });
        this.$store.commit("SET_TOKEN", "example_token");
        this.$router.push("/homepage");
      } else if (this.activeTab === "phone") {
        this.$message.success("登录成功！");
      } else {
        this.$message.error("用户名或密码错误！");
      }
    },
    sendCaptcha() {
      this.$message.success("验证码已发送");
    },
    onForgetPassword() {
      this.$message.info("跳转到忘记密码页面");
    },
  },
};
</script>

<style scoped>
.login-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: url('src/assets/images/start-page/sy1.png') no-repeat center center; /* 替换为图片的实际路径 */
  background-size: cover;
  color: #333;
  padding: 20px;
  box-sizing: border-box;
}

.app-header {
  text-align: center;
  margin-bottom: 20px;
}

.app-header h1 {
  font-size: 24px;
  color: #fff;
  margin: 5px 0;
}

.app-header h2 {
  font-size: 18px;
  color: #b4dff8;
}

.login-content {
  width: 80%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.7);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.login-form .el-input {
  font-size: 14px;
}

.options {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.checkbox-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.forget-link {
  font-size: 14px;
  color: #409eff;
  text-decoration: none;
  margin-left: 10px;
}

.footer-links {
  margin-top: 20px;
  font-size: 12px;
  color: #b4dff8;
  text-align: center;
}

.footer-links a {
  margin: 0 5px;
  color: #fff;
}

.login-center {
  text-align: center;
}

.login-button {
  width: auto;
  padding: 0 20px;
}
</style>
